package db1;

import beans1.Indentbean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class IndentDAO extends ConnBean{
    private Connection connection=null;

    public ArrayList<Indentbean> getAllRecords(){
        ResultSet rs=null;
        Statement stmt=null;
        ArrayList<Indentbean> list=new ArrayList<Indentbean>();
        try {
            //获取数据库连接(url,username,password)
            connection = getConnection();
            if(connection==null)
                System.out.println("error");
            //准备执行数据库查询
            String sql="select * from YY_INDENT";
            //准备SQL执行;
            stmt =connection.createStatement();
            //执行数据库查询，获取结果集
            rs=stmt.executeQuery(sql);
            while(rs.next()){
                Indentbean user=new Indentbean();
                user.setId(rs.getString("id"));
                user.setPid(rs.getString("pid"));
                user.setSchid(rs.getString("schid"));
                user.setDate(rs.getTimestamp("date"));
                user.setState(rs.getString("state"));
                list.add(user);
            }
            //关闭表达式对象
            stmt.close();
            //关闭数据库
            connection.close();

        }catch (SQLException e) {
            e.printStackTrace();
        } finally{
            try{
                if (connection!=null && (!connection.isClosed())){
                    connection.close();
                }
            }catch(SQLException e){
                e.printStackTrace();
            }
        }
        return list;
    }

}
